

#清空数据库
def graphClen(graph):
    graph.delete_all()


# 删除指定结点
def delTheNode(graph, NodeLabel):
    s = "MATCH (n:" + NodeLabel + ") DELETE n"
    graph.run(s)


# 删除指定关系
def delTheRelationship(graph, fromLabel, toLabel, relationshipName):
    s = "MATCH (" + fromLabel + ") -[r:" + relationshipName + "]-> (" + toLabel + ") DELETE r"
    graph.run(s)


# 创建 现象 结点
def create_XianXiang_Node(graph):
    s = "load csv from 'file:///XX_Node.csv' as line " \
        "create(:Phenomenon {Describe:line[0],Location:line[1]}) "
    graph.run(s)



# 创建 总成 结点
def create_ZC_Node(graph):
    s = "load csv from 'file:///ZC_Node.csv' as line " \
        "create(:ZongCheng {Describe:line[0]}) "
    graph.run(s)


# 创建 故障原因 结点
def create_Cause_of_Failure_Node(graph):
    s = "load csv from 'file:///XianXiang_ProblemReason_Relationship.csv' as line " \
        "create(:CauseOfFailure {Describe:line[1],Method:line[2]}) "
    graph.run(s)


#创建  故障现象 -针对-> 总成 关系
def Create_PointTo_Relation(graph):
    s = "load csv from 'file:///ZC_Problem_Relationship.csv' as line " \
        "match (m:Phenomenon) where m.Describe = line[0] " \
        "match (n:ZongCheng) where n.Describe = line[1] " \
        "create (m) -[:PointTo]-> (n)"

    graph.run(s)


#创建  故障现象 -对应-> 故障原因 关系
def Create_Refer_Relation(graph):
    s = "load csv from 'file:///XianXiang_ProblemReason_Relationship.csv' as line " \
        "match (m:Phenomenon) where m.Describe = line[0] " \
        "match (n:CauseOfFailure) where n.Method = line[2] " \
        "create (m) -[:Refer]-> (n)"

    graph.run(s)


# 华丽的分割线————————————————————————————————————————————————————————————————————————————
